<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>求一个词的近反义词 (自己找接口)</title>
</head>

<body>
  <input type="text" placeholder='输入一个词或者词语会出现的近义词和反义词' style="width: 300px;">
  <button>qignqiu1</button>
  <script>
    var btn = document.querySelector('button')
    btn.onclick = () => {
      var inp = document.querySelector('input')
      var val = inp.value
      var xhr = new XMLHttpRequest()
      xhr.open('GET', 'https://apis.tianapi.com/jfwords/index?key=f91ff265d7a7bbed6de9d34babf5abcf&word=' + val)
      xhr.send()
      xhr.onreadystatechange = function () {
        val = ''
        if (xhr.readyState == 4 && xhr.status == 200) {
          var obj = JSON.parse(xhr.responseText)
          alert(inp.value + ' 的近义词是：' + obj.result.jyc + ' 反义词是：' + obj.result.fyc)
        }
      }
    }
  </script>
</body>

</html>